/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;

import java.io.Console;

import core.Client;
import core.Contact;
import core.ContactList;
import core.IMessenger;
import core.Speaker;
import core.Settings;

import ui.Messenger;
import ui.GUIMessenger;


import javax.swing.JOptionPane;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

class /*javaapplication1.*/Main
{
	// JFrame mainFrame;
	public static void main(String[] args) throws java.io.IOException
	{
		//int port = Integer.parseInt(System.console().readLine("Port to listen? "));
        int port = Integer.parseInt((String)JOptionPane.showInputDialog(
                    null,
                    "Port",
                    "Port to listen",
                    JOptionPane.PLAIN_MESSAGE,
                    null,
                    null,
                    "1000"));
		Settings.instance().setPort(port);
		Client.instance().setDaemon(true);
		Client.instance().start();
		Speaker s = new Speaker();
		Client.instance().setSpeaker(s);
		// Messenger messenger = new Messenger(s);
        // messenger.run();
        //ContactList.instance().add("127.0.0.1", port);
        JFrame mainFrame;
		mainFrame = new GUIMessenger(s);
        mainFrame.setTitle(String.format("%d@%s", port, "127.0.0.1"));
		// mainFrame.setTitle("Messenger");
		
		// mainFrame.getContentPane().setLayout(new BoxLayout(mainFrame.getContentPane(), BoxLayout.Y_AXIS));
		// JPanel pane = new JPanel();
		// pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
		// pane.add(new JLabel("To:"));
		// pane.add(new JTextField());
		// mainFrame.add(pane);
		// mainFrame.add(new JTextArea());
		// pane = new JPanel();
		// pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
		// pane.add(new JTextField());
		// pane.add(new JButton("Send"));
		// mainFrame.add(pane);
		
		
        mainFrame.setSize(350, 450);
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        mainFrame.setVisible(true);
	}
}
